package canss.webservice.test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import canss.webservice.model.EventDescription;
import canss.webservice.service.PortalIntraWebServiceControl;
import canss.webservice.service.PortalIntraWebServiceControlBean;

public class svtAjaxGetStatusByCID extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet
{

	private static final long serialVersionUID = -1069530441324063411L;

	public svtAjaxGetStatusByCID()
	{
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doPost(request, response);
	}

	PortalIntraWebServiceControl control;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();
		
		String _cid = request.getParameter("_cid");
		
		try
		{
			control = (control == null) ? new PortalIntraWebServiceControlBean() : control;
			Integer res = control.getContentStatusByID(_cid);
			if(res!=null)
			{
				EventDescription eventdesc = control.getEventDescByEventID(res);
				if(eventdesc!=null && eventdesc.getONELINEDESC()!=null && eventdesc.getONELINEDESC().length()>0)
				{
					out.write(res+": "+eventdesc.getONELINEDESC());
				}else
					out.write(res+": undifined_status");
			}
		}catch(Exception e)
		{
			out.write("error: " + e);
		}
	}
}